/*-------------------------------------
		sPlugin
	    By Scooby, 2010
-------------------------------------*/

local PLUGIN = {}

PLUGIN.Name = "Ban"
PLUGIN.Author = "Scooby"
PLUGIN.Command = "ban"
PLUGIN.Group = 2
PLUGIN.Category = "Punishment"
PLUGIN.Use = "<Player> <Time> <Reason>"
PLUGIN.Format = "string number strnig"
PLUGIN.Menu = { 
	{ 
		title = "Select Player", 
		cont = "#players", 
		apos = 1 
	}, 
	{ 
		title = "Select Time",
		cont = { 5, 10, 30, 60, 1440, 0 },
		apos = 2
	},
	{
		title = "Select Reason", 
		cont = { "Spammer", "Annoying", "Hacker", "Retard", "Asshole" }, 
		apos = 3
	} 
}

function PLUGIN:Main( pl, args )
	
	local ply = spl:FindPly( args[1] )
	local time = tonumber( args[2] )
	local reason = table.concat( args, " ", 3 )
	
	if( #ply == 0 ) then
		spl:PrintC( spl.red, spl.fnp )
		return false
	elseif( #ply > 1 ) then
		spl:PrintC( spl.red, spl.fmp )
		return false
	end
	
	if( #reason == 0 ) then
		reason = "No Reason Specified"
	end
	
	if( !spl.info.bans ) then spl.info.bans = {} end
	spl.info.bans[ ply[1]:SteamID() ] = {}
	spl.info.bans[ ply[1]:SteamID() ] = {
		 Time  = time,
		 Reason  = reason,
		 Admin  = pl:Nick(),
		 EndTime  = os.time() + time * 60,
		 Banned  = true
	}
	spl:SaveInfo()
	
	if( gatekeeper ) then
		if( time != 0 ) then
			gatekeeper.Drop( ply[1]:UserID(), "Banned For "..time.." Minutes ( "..reason.." )" )
		else
			gatekeeper.Drop( ply[1]:UserID(), "Permanatly Banned ( "..reason.." )" )
		end
	else
		if( time != 0 ) then
			ply[1]:Kick( "Banned For "..time.." Minutes ( "..reason.." )" )
		else
			ply[1]:Kick( "Permanatly Banned ( "..reason.." )" )
		end
	end
	
	if( time != 0 ) then
		spl:PrintC( spl.red, ply[1]:Nick(), spl.white, " Was Banned By ", spl.blue, pl:Nick(), spl.white, " For ", spl.green, tostring( time ), spl.white, " Minutes ( "..reason.." )" )
	else
		spl:PrintC( spl.red, ply[1]:Nick(), spl.white, " Was ",spl.red, "Permanatly ", spl.white, "Banned By ", spl.blue, pl:Nick(), "( "..reason.." )" )
	end
end
		
hook.Add( "PlayerAuthed", "Admin2010CheckBan", function( ply, st, un )
	if( spl.info.bans[ st ] ) then
		if( spl.info.bans[ st ] [ "Banned" ] ) then
			if( spl.info.bans[ st ] [ "EndTime" ]  > os.time() ) then
				ply:Kick( "You Are Banned For Another "..tostring( spl.info.bans[ st ] [ "Time" ] - os.time()* 60).." Minutes" )
			elseif( spl.info.bans[ st ] [ "EndTime" ] == 0  ) then
				ply:Kick( "You Are Permanatly Banned From This Server" )
			else
				spl.info.bans[ st ] [ "Banned" ] = false
			end
		end	
	end
end)

spl:AddPlugin( PLUGIN )